#include <AknIconArray.h>

#include "SettingsListBox.h"
#include "AppUi.h"

CSettingsListBox::CSettingsListBox(MSettingsObserver* aObserver)
{
	iObserver = aObserver;
}

TKeyResponse CSettingsListBox::OfferKeyEventL(const TKeyEvent& aKeyEvent,TEventCode aType)
{
	TInt code = aKeyEvent.iCode;
	TKeyResponse res = CAknSettingStyleListBox::OfferKeyEventL(aKeyEvent, aType);
	TInt ind = CurrentItemIndex();
	if (aType != EEventKey)
		return res;

	switch (code)
	{
		case EKeyUpArrow:
		case EKeyDownArrow:
			iObserver->SelectedIndexChangedL(ind);
			break;
		case EKeyOK:
			if (ind != KErrNotFound)
			{
				DefAppUi;
				if (appUi->EnoughSpace())
				{
					iObserver->ShowSettingItemL(ind);
				}
			}	
			break;
		case EKeyLeftArrow:
		case EKeyRightArrow:
			return EKeyWasNotConsumed;
	}
	return res;
}
